checkout: Add --allow-noent option
authorColin Walters <walters@verbum.org>
Wed, 1 May 2013 16:15:02 +0000 (12:15 -0400)
committerColin Walters <walters@verbum.org>
Wed, 1 May 2013 16:15:02 +0000 (12:15 -0400)
This is useful for the gnome-ostree build system where each build is
one commit, but it's split up into /runtime /devel /debug etc. trees.
Ideally we wouldn't have a /debug subdirectory for "noarch"
components for example.

So add an option to not error out if the given path doesn't exist in
the commit.

src/ostree/ot-builtin-checkout.c
tests/t0000-basic.sh

index 2b63851dc16a608a247333b0048a9c1d7285f585..a90795c959e3e23e46806353c39011b6b3e9c296 100644 (file)
@@ -30,6 +30,7 @@
 #include <glib/gi18n.h>
 
 static gboolean opt_user_mode;
+static gboolean opt_allow_noent;
 static gboolean opt_no_triggers;
 static char *opt_subpath;
 static gboolean opt_union;
@@ -40,6 +41,7 @@ static GOptionEntry options[] = {
   { "user-mode", 'U', 0, G_OPTION_ARG_NONE, &opt_user_mode, "Do not change file ownership or initialize extended attributes", NULL },
   { "subpath", 0, 0, G_OPTION_ARG_STRING, &opt_subpath, "Checkout sub-directory PATH", "PATH" },
   { "union", 0, 0, G_OPTION_ARG_NONE, &opt_union, "Keep existing directories, overwrite existing files", NULL },
+  { "allow-noent", 0, 0, G_OPTION_ARG_NONE, &opt_allow_noent, "Do nothing if specified path does not exist", NULL },
   { "no-triggers", 0, 0, G_OPTION_ARG_NONE, &opt_no_triggers, "Don't run triggers", NULL },
   { "from-stdin", 0, 0, G_OPTION_ARG_NONE, &opt_from_stdin, "Process many checkouts from standard input", NULL },
   { "from-file", 0, 0, G_OPTION_ARG_STRING, &opt_from_file, "Process many checkouts from input file", NULL },
@@ -89,6 +91,7 @@ process_one_checkout (OstreeRepo           *repo,
 {
   gboolean ret = FALSE;
   ProcessOneCheckoutData data;
+  GError *tmp_error = NULL;
   ot_lobj OstreeRepoFile *root = NULL;
   ot_lobj OstreeRepoFile *subtree = NULL;
   ot_lobj GFileInfo *file_info = NULL;
@@ -106,9 +109,21 @@ process_one_checkout (OstreeRepo           *repo,
 
   file_info = g_file_query_info ((GFile*)subtree, OSTREE_GIO_FAST_QUERYINFO,
                                  G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
-                                 cancellable, error);
+                                 cancellable, &tmp_error);
   if (!file_info)
-    goto out;
+    {
+      if (opt_allow_noent
+          && g_error_matches (tmp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
+        {
+          g_clear_error (&tmp_error);
+          ret = TRUE;
+        }
+      else
+        {
+          g_propagate_error (error, tmp_error);
+        }
+      goto out;
+    }
 
   data.loop = g_main_loop_new (NULL, TRUE);
   data.error = error;
index bed1107c93ef60d40d82b843b884dd1a9514b9c2..60c20a6730331633b6952776c76715c18b406998 100755 (executable)
@@ -19,7 +19,7 @@
 
 set -e
 
-echo "1..28"
+echo "1..30"
 
 . libtest.sh
 
@@ -208,3 +208,14 @@ rm -rf test2-checkout
 parent_rev_test2=$(ostree --repo=repo rev-parse test2)
 ${CMD_PREFIX} ostree --repo=shadow-repo checkout "${parent_rev_test2}" test2-checkout
 echo "ok checkout from shadow repo"
+
+cd ${test_tmpdir}
+rm -f expected-fail
+$OSTREE checkout test2 --subpath /enoent 2>/dev/null || touch expected-fail
+assert_has_file expected-fail
+echo "ok subdir enoent"
+
+cd ${test_tmpdir}
+$OSTREE checkout test2 --allow-noent --subpath /enoent 2>/dev/null
+echo "ok subdir noent"
+